package com.tanhua.controller;

import com.tanhua.interceptor.UserHolder;
import com.tanhua.service.MessageService;
import com.tanhua.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.tanhua.vo.UserInfoVo;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @GetMapping("/userinfo")
    public ResponseEntity findUserInfoByHuanxinId(String huanxinId){
        UserInfoVo userInfoVo = messageService.findUserInfoByHuanxinId(huanxinId);
        return ResponseEntity.ok(userInfoVo);

    }

    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        Long friendId = Long.valueOf(map.get("userId").toString());
        messageService.createFriends(friendId);
        return ResponseEntity.ok(null);

    }


    @GetMapping("/contacts")
    public ResponseEntity friendList(@RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer pagesize,
                                     String keyword){
        PageResult pr = messageService.friendList(page,pagesize,keyword);
        return ResponseEntity.ok(pr);
    }


}
